package programs.expression.implementedClasses;

import programs.expression.superClasses.Expression;
import programs.expression.superClasses.ExpressionType;
import programs.expression.superClasses.UnaryDoubleExpression;
import game.SpaceObject;

public class GetX extends UnaryDoubleExpression {

	public GetX(Expression operand) {
		super(operand);
	}

	@Override
	public Object getValue() {
		SpaceObject object = ((SpaceObject) getSubExpressionAt(1).getValue());
		return object.getxPosition();
	}

	@Override
	public boolean isValidExpression() {
		return ( super.isValidExpression() && (ExpressionType.ENTITY == getSubExpressionAt(1).getReturnType())
				&& ( getSubExpressionAt(1).getValue() != null ) ) || (getSubExpressionAt(1) instanceof Self);
	}

}
